import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:simple_animations/simple_animations.dart';

import 'controls/login_animation_controller.dart';
import 'controls/login_form_controller.dart';
import 'widgets/login_header_widget.dart';
import 'widgets/login_form_widget.dart';
import 'widgets/social_login_widget.dart';
import 'widgets/login_footer_widget.dart';
import '../home/home_screen.dart';

class LoginScreen extends StatefulWidget {
  const LoginScreen({super.key});

  @override
  State<LoginScreen> createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> with TickerProviderStateMixin {
  late final LoginAnimationController _animationController;
  late final LoginFormController _formController;

  @override
  void initState() {
    super.initState();
    _animationController = LoginAnimationController();
    _animationController.initialize(this);
    _formController = LoginFormController();
  }

  @override
  void dispose() {
    _animationController.dispose();
    _formController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: LayoutBuilder(
        builder: (context, constraints) {
          final isLargeScreen = constraints.maxWidth > 800;
          return Container(
            decoration: const BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
                colors: [Color(0xFFEFF6FF), Colors.white],
              ),
            ),
            child: SafeArea(
              child: SizedBox(
                width: constraints.maxWidth,
                child: Row(
                  children: [
                    if (isLargeScreen)
                      LoginHeaderWidget(
                        fadeAnimation: _animationController.fadeAnimation,
                        iconRotationAnimation: _animationController.iconRotationAnimation,
                        floatingOffset: _animationController.floatingOffset,
                        scaleAnimation: _animationController.scaleAnimation,
                        isLargeScreen: isLargeScreen,
                      ),
                    LoginFormWidget(
                      formController: _formController,
                      animationController: _animationController,
                      isLargeScreen: isLargeScreen,
                    ),
                  ],
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}
